package com.itheima.controller;

import com.itheima.dto.MoneyInfoParam;
import com.itheima.dto.OrderDelDto;
import com.itheima.dto.OrderListDto;
import com.itheima.dto.ReceiverInfoParam;
import com.itheima.pojo.OmsOrder;
import com.itheima.service.OmsOrderService;
import com.itheima.vo.OrderVo;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OmsOrderController {
    @Autowired
    private OmsOrderService omsOrderService;

    /**
     * 批量删除订单
     *
     * @param ids
     * @return
     */
    @PostMapping("delete")
    public ResponseEntity deleteOrders(Integer[] ids) {

        omsOrderService.deleteLogic(ids);
        return ResponseEntity.ok(Result.success(null));

    }


    //order/list

    /**
     * 查询订单
     *
     * @return
     */
    @GetMapping("list")
    public ResponseEntity listPage(OrderListDto orderListDto) {
        PageResultVo<OmsOrder> pageResultVo = omsOrderService.listPage(orderListDto);
        return ResponseEntity.ok(Result.success(pageResultVo));
    }

    /**
     * 批量关闭订单
     * @return
     */
    @PostMapping("update/close")
    public ResponseEntity updateClose(String note,Integer [] ids) {

        omsOrderService.closeByIds(ids,note);
        return ResponseEntity.ok(Result.success(null));

    }

    /**
     * 批量发货
     * @param deliveryParamList
     * @return
     */
///order/update/delivery
    @PostMapping("/update/delivery")
    public ResponseEntity updateDel(@RequestBody List<OrderDelDto> deliveryParamList){
        omsOrderService.updateDel(deliveryParamList);
        return ResponseEntity.ok(Result.success(null));
    }


    @PostMapping("/update/moneyInfo")
    public ResponseEntity moneyInfo(@RequestBody MoneyInfoParam moneyInfoParam){
        omsOrderService.moneyInfo(moneyInfoParam);
        return ResponseEntity.ok(Result.success(null));
    }


    /**
     * 修改保存备注
     * @param id
     * @param note
     * @param status
     * @return
     */
    @PostMapping("/update/note")
    public ResponseEntity updateNote(Integer id,String note,Integer status){
        omsOrderService.updateAndSave(id,note,status);
        return ResponseEntity.ok(Result.success(null));
    }


    /**
     * 修改收货人信息 并将操作记录保存到记录表中
     * @param
     * @param
     * @param
     * @return
     */
    @PostMapping("/update/receiverInfo")
    public ResponseEntity receiverInfo(@RequestBody ReceiverInfoParam receiverInfoParam ){
        omsOrderService.updateReceiverInfo(receiverInfoParam);
        return ResponseEntity.ok(null);
    }

    /**
     * 根据id 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ResponseEntity getOderInfoById(@PathVariable("id")Integer id){
        OrderVo orderVo=omsOrderService.getById(id);
        return ResponseEntity.ok(Result.success(orderVo));
    }

}
